package prv.pursuivant.core.impl;

import java.util.Date;

import prv.pursuivant.core.Achievement;
import prv.pursuivant.core.Toon;

/**
 * Already achieved achievement.
 * 
 * Achievement object is a single case, like "Kwinto achieved "The
 * Immortal" on 08/03/2009".
 * 
 * @author Kwinto
 * @see prv.pursuivant.core.impl.AbstractAchievType
 * 
 */

public class AchievementImpl implements Achievement {

	@SuppressWarnings("deprecation")
	@Override
	public String toString() {
		return toon.getName() + ":" + id + ":" + date.toLocaleString();
	}

	/**
	 * Toon. This is for backward link, for future use (maybe)
	 */
	private final Toon toon;

	/**
	 * Date of achievement
	 */
	private final Date date;

	/**
	 * Id of achievement type.
	 * 
	 * @see prv.pursuivant.core.impl.AbstractAchievType
	 */
	private final String id;

	/**
	 * @param toon
	 * @param date
	 * @param id
	 */
	public AchievementImpl(Toon toon, Date date, String id) {
		this.toon = toon;
		this.date = date;
		this.id = id;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see prv.pursuivant.core.Achievement#getToon()
	 */
	public Toon getToon() {
		return this.toon;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see prv.pursuivant.core.Achievement#getDate()
	 */
	public Date getDate() {
		return this.date;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see prv.pursuivant.core.Achievement#getId()
	 */
	public String getId() {
		return this.id;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj instanceof AchievementImpl) {
			Achievement achiev = (Achievement) obj;
			return this.getDate().equals(achiev.getDate())
					&& this.getId().equals(achiev.getId())
					&& this.getToon().getName().equals(
							achiev.getToon().getName());
		}
		return false;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return getDate().hashCode() ^ getToon().hashCode() ^ getId().hashCode();
	}

}
